package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Letter;
import cn.wolfcode.trip.base.mapper.LetterMapper;
import cn.wolfcode.trip.base.query.LetterQueryObject;
import cn.wolfcode.trip.base.service.ILetterService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class LetterServiceImpl implements ILetterService {
    @Autowired
    private LetterMapper letterMapper;

    @Override
    public void insertByUserId(Letter letter) {
        letter.setMessagesDate(new Date());
        letterMapper.insert(letter);
    }

    @Override
    public int notletters(Long userId) {
        return letterMapper.notletters(userId);
    }

    @Override
    public PageInfo<Letter> query(LetterQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        List<Letter> list = letterMapper.query(qo);
        return new PageInfo<Letter>(list);
    }

    @Override
    public void updateIsViewed(Long userId) {
        letterMapper.updateIsViewed(userId);
    }
}
